/**
 * Created by levy on 16/6/16.
 */
import {shopping} from "../const/shopping.js";
import RichText from "../components/RichText.js";
import Radio from "../components/form/Radio";

const lf = liefeng,
    R = React,
    RC = React.createClass,
    ajax = lf.utils.ajax;

const goodsId = lf.utils.getUrlParam('goodsId');
/**
 * props:
 *  user
 */
const Root = RC({
    getInitialState() {
        return {
            itemDetail: {}, //商品基本信息
            attrDetail: [], //属性信息
            cartNum: '',
        }
    },
    getItemDetail() {
        ajax({
            url: shopping.api.prefix + shopping.api.itemDetail,
            data: {
                goodsId: goodsId
            },
            success: (data) => {
                if (data.code != 200) alert('没有商品数据');
                else {
                    this.setState({itemDetail: data.data});
                }
            }
        });
    },
    getAttrDetail() {
        ajax({
            url: shopping.api.prefix + shopping.api.attrDetail,
            data: {
                goodsId: goodsId
            },
        }, null, (data) => {

            this.setState({
                attrDetail: data,
            })
        });
    },

    componentWillMount() {
        this.getItemDetail();
    },
    tapFn(){
        if (lf.utils.getSys() == "IOS") {
            lf.bridgeJs.doClose();
        }
        lf.bridgeJs.callAppHandler('scanQRCode', null, function (data) {
            var url = lf.utils.getProtocol(data.result);
            lf.appJs.doLocation(url, '猜灯谜');
        })
        $('.page-success-to').css({
            display: 'none'
        })
    },
    render() {
        const data = this.state.itemDetail;
        return <div className="shopping item-detail">

            <div className="page-success-to" ref="payPage">
                <div className="center-box-to">
                    <div className="img-detail split-line">
                        {
                            data && data.goodsDesc ?
                                <RichText text={data.goodsDesc}/>
                                :
                                <div className="row light-gray"></div>
                        }
                    </div>
                    <div className="answer">{data && data.keywords}</div>
                    <div className="prompt">手慢了 奖品已飘过!</div>
                    <ul className="check-btn-to">
                        <li onTouchEnd={this.tapFn}><a href="#">继续参与</a></li>
                    </ul>
                </div>
            </div>

        </div>

    }
});

lf.appJs.getUser(function (user) {
    R.render(<Root user={user}/>, document.getElementById('root'));
});



